package com.zx.ishopping.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * JSON文件读取工具类
 */
public class JsonUtil {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    /**
     * 读取省市区JSON数据
     * @param fileName 文件名（如 provinces.json）
     * @return 解析后的列表数据
     */
    public static List<Map<String, String>> readAreaJson(String fileName) throws IOException {
        Resource resource = new ClassPathResource("data/" + fileName);
        try (InputStream inputStream = resource.getInputStream()) {
            return objectMapper.readValue(inputStream, new TypeReference<List<Map<String, String>>>() {});
        }
    }
}